﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace SkypeConnector
{
    public partial class Configuration : Form
    {
        public Configuration()
        {
            InitializeComponent();
            this.SuspendLayout();
            this.Visible = true;
            this.StartPosition = FormStartPosition.Manual;
            this.FormBorderStyle = FormBorderStyle.None;

            System.Drawing.Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
            this.Location = new Point(
                   workingRectangle.Width - this.Width - 150, workingRectangle.Height - this.Height);

            this.ResumeLayout();

            tbServer.Text = ConfigurationManager.AppSettings["CRMServer"];
            int https = Int32.Parse(ConfigurationManager.AppSettings["useHTTPS"]);
            if (https == 0) cbHTTPS.Checked = false;
            else if (https == 1) cbHTTPS.Checked = true;
            tbPort.Text = ConfigurationManager.AppSettings["CRMServerPort"];
            tbOrgName.Text = ConfigurationManager.AppSettings["CRMOrgName"];
            tbDomain.Text = ConfigurationManager.AppSettings["CRMDomain"];
            tbUsername.Text = ConfigurationManager.AppSettings["CRMUsername"];
            tbPassword.Text = ConfigurationManager.AppSettings["CRMPassword"];
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            ConfigurationManager.AppSettings["CRMServer"] = tbServer.Text;
            ConfigurationManager.AppSettings["CRMServerPort"] = tbPort.Text;
            ConfigurationManager.AppSettings["CRMOrgName"] = tbOrgName.Text;
            ConfigurationManager.AppSettings["CRMDomain"] = tbDomain.Text;
            ConfigurationManager.AppSettings["CRMUsername"] = tbUsername.Text;
            ConfigurationManager.AppSettings["CRMPassword"] = tbPassword.Text;
        }
    }
}
